<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>日志流</title>
</head>
<body>
<h2>实时日志</h2>
<pre id="logArea"></pre>

<script>
    // 使用 XMLHttpRequest 接收服务器推送的日志流
    function fetchStreamXHR() {
        const xhr = new XMLHttpRequest();
        xhr.open("GET", "http://localhost:9002/log-stream", true);
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 3 && xhr.status === 200) {
                console.log("Received:", xhr.responseText);
                const logArea = document.getElementById('logArea');
                logArea.textContent += xhr.responseText + "\n";
            }
        };
        xhr.send();
    }

    fetchStreamXHR();
</script>
</body>
</html>